import {createRouter, createWebHashHistory} from "vue-router";
import yFree from '../YFree/YFree.js'
import Global from '../Global.js'
import index from '../components/main/index.vue'
import home from '../components/main/home.vue'

let router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {path: '/', name: 'index', component: index},
        {path: '/home', name: 'home', component: home},
    ]
})

router.beforeEach((to, from, next) => {
    if (to.name === Global.IFinal.Page.index) next();
    else {
        if (Global.AppUtils.readUserModel() != null) next();
        else {
            yFree.yShowBuilder("身份过期，请重新登录", (isConfirm) => {
                if (isConfirm) {
                    next({name: Global.IFinal.Page.index});
                    yFree.yRefresh()
                }
            }, false, "重新登录");
        }
    }
});

export default router;
